import numpy as np
from jqdatasdk import *

import time
from ZIndex.tool import Util
import pandas as pd

# auth('18727012661','Cptbtptp123456')
auth('18995532338','Znufe2006@')

# display_name = get_security_info('000001.XSHE').display_name
# 'sz.300008', 'sz.002623', 'sz.000665', 'sz.002411', 'sz.300222'
# print(display_name)


# 读取csv文件，获取股票代码
stockCodeList = pd.read_csv(r'stockCode.csv',sep=',', header=None, names=['stock'])

security_list = normalize_code(stockCodeList['stock'].values.tolist())

print(security_list)

dayCount = Util.day_count('20150101', '20220120')

for i in np.arange(dayCount):
    # print(i)
    searchDate = Util.getYesterday(int(i))
    print(searchDate)
    df = get_fundamentals(query(
        # valuation, income
        valuation
    ).filter(
        # 这里不能使用 in 操作, 要使用in_()函数
        valuation.code.in_(security_list)
    ), date=searchDate)

    time.sleep(5)

    Util.dataFrameToCsv(df, "stock_valuation.csv", True)


# Util.dataFrameToCsv(result, "/result/Sign.csv", True, columns=columns)


























